/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年1月25日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20200125_shellsort
 * @Desc
 * @author 52489
 * @date 2020年1月25日
 * @Version V1.0
 */
public class A20200125_shellsort {
    public static void main(String[] args) {
        int nums[] = { 3, 1, 2, 7, 5, 4 };
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }

    /**
     * @param nums
     */
    private static void sort(int[] nums) {
        for (int step = nums.length / 2; step > 0; step /= 2) {
            for (int j = 0; j < step; j++) {
                for (int i = step; i < nums.length; i += step) {
                    int tmp = nums[i];
                    int k = i - step;
                    while (k >= 0 && nums[k] > tmp) {
                        nums[k + step] = nums[k];
                        k -= step;
                    }
                    nums[k + step] = tmp;
                }
            }
        }
    }

}
